package com.zy.ivideo.repository;

import com.zy.ivideo.entity.CommentEntity;
import com.zy.ivideo.entity.ReplyEntity;
import com.zy.ivideo.entity.ResponseEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface ReplyRepository extends JpaRepository<ReplyEntity,Long> {

    @Query(nativeQuery=true,value="select * from b_reply where commentid=?1")
    List<ReplyEntity> getReplyByCommentId(long commentid);

    @Transactional
    @Modifying(clearAutomatically=true)
    @Query(value="update b_reply set agreenum=agreenum+?2 where id=?1",nativeQuery=true)
    int modifyAgreeNum(int replyid,int num);

    @Transactional
    @Modifying(clearAutomatically=true)
    @Query(value="delete  from b_reply where commentid=?1",nativeQuery=true)
    int removeByCommentId(long commentid);
}
